//
//  GuestView.m
//  MyProject
//
//  Created by dllo on 15/11/3.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "GuestView.h"
#import "GuestCollectionCell.h"
#import "UIImageView+WebCache.h"

#import "GuestSecViewController.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height

@implementation GuestView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
    
}

- (void)create{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(WIDTH / 100 * 45, HEIGHT / 100 * 20);
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0,WIDTH, HEIGHT) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.collectionView];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.collectionView registerClass:[GuestCollectionCell class] forCellWithReuseIdentifier:@"reuse"];
    
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.arrayGuest.count;
}



- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    GuestCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor lightGrayColor];
    [cell.image sd_setImageWithURL:self.arrayGuest[indexPath.row][@"img"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    cell.label.text = self.arrayGuest[indexPath.row][@"name"];
    return cell;

}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    GuestSecViewController * gueSec = [[GuestSecViewController alloc] init];
    [self.VC.navigationController pushViewController:gueSec animated:YES];
    
    
    gueSec.dic = self.arrayGuest[indexPath.row];
    
}







@end
